<template>
  <div>
    <van-popup 
      v-model="visible" 
      position="bottom" 
      :style="{ height: 'auto' }"
      @close="handleCancel">
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <div style="margin-top:10px;width:100%;">
            <a-form-item label="用户账号">
              <a-input placeholder="请输入用户账号" v-model="queryParam.username"></a-input>
            </a-form-item>
          </div>
          <a-row>
            <a-col :span="24">
              <div style="margin-bottom:5px;">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <a-button type="primary" @click="handleOk" style="margin-left: 8px">确定</a-button>
              </div>
            </a-col>
          </a-row>
        </a-form>
      </div>

      
      <div>
        <van-radio-group v-model="radio" class="list">
          <van-list
            v-model="loading"
            :finished="finished"
            offset="30"
            finished-text="没有更多了"
            @load="downLoadData"
            :immediate-check="false">
            <van-radio
              style="padding: 0 20px;"
              v-for="(item,i) in dataSource1"
              :key="i"
              :name="i">
              <div class="userItem">
                <span style="width:20%;">{{ item.realname }}</span>
                <span style="width:40%;">{{ item.phone }}</span>
                <span style="width:40%;">{{ item.departName }}</span>
              </div>
            </van-radio>
          </van-list>
        </van-radio-group>
      </div>
    </van-popup>


  </div>
</template>

<script>
  import {filterObj} from '@/utils/util'
  import {getAction} from '@/api/manage'

  export default {
    name: "SelectDepartModal",
    data() {
      return {
        radio: '',
        finished: false,
        title: "",
        names: [],
        visible: false,
        placement: 'right',
        description: '',
        width:'50%',
        // 查询条件
        queryParam: {},
        //职务条件
        post:'',
        // 表头
        columns1: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '用户账号',
            align: "center",
            width: 100,
            dataIndex: 'username'
          },
          {
            title: '用户名称',
            align: "center",
            width: 100,
            dataIndex: 'realname'
          },
          {
            title: '电话',
            align: "center",
            width: 100,
            dataIndex: 'phone'
          },
          {
            title: '部门',
            align: "center",
            width: 150,
            dataIndex: 'departName'
          }
        ],
        //数据集
        dataSource1: [],
        // 分页参数
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        loading: false,
        selectedRowKeys: [],
        selectedRows: [],
        url: {
          list: "/sys/user/queryUserByDepart",
        }
      }
    },
    created() {
      //this.loadData();
    },
    methods: {
      downLoadData(){
        this.ipagination.current++;
        this.finished = false
        this.loadData()
      },
      searchQuery() {
        this.loadData(1);
      },
      searchReset() {
        this.queryParam = {};
        this.loadData(1);
      },
      handleCancel() {
        this.visible = false;
      },
      handleOk() {
        this.selectedRows = [
          this.dataSource1[this.radio]
        ]
        this.selectedRows = [
          this.dataSource1[this.radio]
        ]
        this.$emit("selectFinished", this.selectedRows[0]);
        this.visible = false;
      },
      add() {
        this.visible = true;
        this.loadData(1);
      },
      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.radio = ''
          this.dataSource1 = []
          this.ipagination.current = 1;
          this.finished = false
        }
        var params = this.getQueryParams();//查询条件
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource1 = [...this.dataSource1, ...res.result.records];
            this.ipagination.total = res.result.total;
          }
          this.loading = false
          if(res.result.records.length<10){
            this.finished = true;
          }
        })
      },
      getQueryParams() {
        var param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.post = this.post;
        return filterObj(param);
      },
      getQueryField() {
        //TODO 字段权限控制
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectionRows
      },
    }
  }
</script>
<style lang="less" scoped>
  .list{
    overflow-y: scroll;
    height:380px;
    .userItem{
      display:flex;
      justify-content:space-between;
      height: 40px;
      line-height: 40px;
      border-top: 1px solid #f6f6f6;
      span{
        text-align:left;
      }
    }
  }
  .list /deep/ .van-radio__label{
    width:calc(100% - 30px);
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .table-page-search-wrapper{
    padding: 0 20px;
  }
  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
  .ant-form-item{
    margin-bottom:10px !important;
  }
  .table-page-search-submitButtons{
    margin-bottom:10px !important;
  }
</style>